//
//  TaskItemCell.m
//  chart
//
//  Created by 曾斌 on 16/3/24.
//  Copyright (c) 2016年 xu. All rights reserved.
//

#import "TaskItemCell.h"
#import "TSTaskModel.h"
#define MESSAGE_CELL_GAP 5.f
#define TIME_LABEL_WIDTH 160.f
#define SECTION_LABEL_WIDTH (currentDeviceWidth-TIME_LABEL_WIDTH-STATUS_LABEL_WIDTH-2*MESSAGE_CELL_GAP-2*MARGIN_LEFT)
#define STATUS_LABEL_WIDTH 80.f

@implementation TaskItemCell{
    UILabel *timeLabel;
    UILabel *titleLabel;
    UILabel *statusLabel;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addtimeLabel];
        [self addtitleLabel];
        [self addStatusLabel];
    }
    
    return self;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier isHeader:(BOOL) isHeader{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addtimeLabel];
        [self addtitleLabel];
        [self addStatusLabel];
        [self setRecycleHeadContent];
    }
    return self;
}

-(void)setRecycleHeadContent
{
    if (timeLabel) {
        [timeLabel setText:[NSString stringWithFormat:@"%@", @"时间"]];
    }
    
    if (titleLabel) {
        [titleLabel setText:[NSString stringWithFormat:@"%@", @"标题"]];
    }
    if (statusLabel) {
        [statusLabel setText:[NSString stringWithFormat:@"%@", @"状态"]];
    }
    
}

- (void)addtimeLabel
{
    timeLabel = [self createLabel:CGRectMake(MARGIN_LEFT, 0, TIME_LABEL_WIDTH, CGRectGetHeight(self.bounds)) TextAignment:NSTextAlignmentLeft];
    [self.contentView addSubview:timeLabel];
}

- (void)addtitleLabel
{
    titleLabel = [self createLabel:CGRectMake(CGRectGetMaxX(timeLabel.frame)+MESSAGE_CELL_GAP, 0, SECTION_LABEL_WIDTH, CGRectGetHeight(self.bounds)) TextAignment:NSTextAlignmentCenter];
    [self.contentView addSubview:titleLabel];
}

- (void)addStatusLabel
{
    statusLabel = [self createLabel:CGRectMake(CGRectGetMaxX(titleLabel.frame)+MESSAGE_CELL_GAP, 0, STATUS_LABEL_WIDTH, CGRectGetHeight(self.bounds)) TextAignment:NSTextAlignmentRight];
    [statusLabel setTextAlignment:NSTextAlignmentRight];
    [self.contentView addSubview:statusLabel];
}

- (UILabel *)createLabel:(CGRect)frame TextAignment:(NSTextAlignment)alignment
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    [label setText:@""];
    label.textAlignment = alignment;
    [label setFont:FONT(12.f)];
    
    return label;
}

- (void)setModel:(TSTaskModel *)model
{
    
    if (timeLabel) {
       [timeLabel setText:[TSTools getDateNoYearByTime:model.timeBegin]];
    }
  
    
    if (statusLabel) {
        [statusLabel setText:[TSTools getTaskStatus:model.status]];
    }
    if(titleLabel){
        [titleLabel setText:[NSString stringWithFormat:@"%@", model.title]];
    }
}

@end
